﻿Public Class LyricsHelper

    Private Shared KanaDictionary As New SortedDictionary(Of Char, Char)

    Shared Sub New()
        Dim katakana = "ヲァィゥェォャュョッアイウエオナニヌネノマミムメモヤユヨラリルレロワンカキクケコサシスセソタチツテトハヒフヘホガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポ"
        Dim hiragana = "をぁぃぅぇぉゃゅょっあいうえおなにぬねのまみむめもやゆよらりるれろわんかきくけこさしすせそたちつてとはひふへほがぎぐげござじずぜぞだぢづでどばびぶべぼぱぴぷぺぽ"

        'Dim harfKana = "ｶﾞｷﾞｸﾞｹﾞｺﾞｻﾞｼﾞｽﾞｾﾞｿﾞﾀﾞﾁﾞﾂﾞﾃﾞﾄﾞﾊﾞﾋﾞﾌﾞﾍﾞﾎﾞﾊﾟﾋﾟﾌﾟﾍﾟﾎﾟｳﾞ"
        'Dim harfKanaToHiragana = "がぎぐげござじずぜぞだぢづでどばびぶべぼぱぴぷぺぽヴ"

        For i = 0 To katakana.Length - 1
            KanaDictionary.Add(katakana(i), hiragana(i))
        Next

        'For i = 0 To harfKanaToHiragana.Length
        '    KanaDictionary.Add(harfKana.Substring(i * 2, 2), harfKanaToHiragana(i))
        'Next

    End Sub


    Public Shared Function ToHiragana(ByVal text As String, ByVal replaceTable As IDictionary(Of String, String)) As String

        For Each word In replaceTable
            text = text.Replace(word.Key, word.Value)
        Next

        Dim newText = New System.Text.StringBuilder
        For Each c In text
            If KanaDictionary.ContainsKey(c) Then
                newText.Append(KanaDictionary(c))
            Else
                newText.Append(c)
            End If
        Next
        Return newText.ToString

    End Function

End Class
